'use strict';
module.exports = {
	/**
	 * 获取动态评论列表
	 * @url client/comment/kh/getCommentsByDynamic 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			db,
			_
		} = util;
		let {
			uid
		} = data;
		let res = {
			code: 0,
			msg: "",
			data: {}
		};
		// 业务逻辑开始-----------------------------------------------------------
		let comments = await vk.baseDao.selects({
			dbName: "wy-dynamic-comments", // 主表名
			getMain: true, // 是否只返回rows数据，默认false
			getCount: true,
			// 主表where条件
			whereJson: {
				dynamic_id: data.dynamic_id
			},
			// 主表字段显示规则
			fieldJson: {},
			// 主表排序规则
			sortArr: [{
				"name": "_add_time",
				"type": "desc"
			}],
			// 副表列表
			foreignDB: [{
				dbName: "uni-id-users",
				localKey: "user_id",
				foreignKey: "_id",
				as: "commenter",
				limit: 1,
				fieldJson: {
					avatar: true,
					nickname: true
				},
			}]
		});

		res.data = comments;

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
